#ifndef COMMON_CONTEXT_HELPER_H
#define COMMON_CONTEXT_HELPER_H

#include <crow/json.h>

#include "common/elements/element.h"
#include "common/log/log.h"
#include "common/more/json.h"

namespace Common
{

typedef crow::json::wvalue ContextValue;

crow::json::wvalue contextFromElement(const Elements::ElementPtr element);

template<typename T>
crow::json::wvalue contextFromElements(const T elements)
{
    if (elements.empty())
        return {};

    std::vector<crow::json::wvalue> jsonElements;
    jsonElements.reserve(elements.size());
    for (const auto element : elements)
        jsonElements.push_back(contextFromElement(element));

    return crow::json::wvalue(jsonElements);
}

class ContextList final
{
public:
    std::vector<ContextValue> data() const;
    ContextList& operator<<(const ContextValue& value);

private:
    std::vector<ContextValue> m_data;
};

} // namespace Common

#endif // COMMON_CONTEXT_HELPER_H
